<template>
  <PageContainer>
    <view class="container">
      <Header title="业务结果" />
      <TResult
        types="waiting"
        :title="title"
        :content="content"
        cancel-text="查看我的意向"
        :confirm-text="confirmText"
        :confirm-open-type="routeOptions?.type == ApplicationTypeEnum.match ? 'share' : void 0"
        @cancel="handleCancel"
        @confirm="handleConfirm"
      />
    </view>
  </PageContainer>
</template>

<script lang="ts" setup>
  /* applyCooperationResult 申请合作结果页 */
  import Header from '@/components/Header/index.vue';
  import PageContainer from '@/components/PageContainer/index.vue';
  import TResult from '@/components/TResult/index.vue';
  import { ApplicationTypeEnum } from '@/enums/businessOpportunitiesEnum';
  import { useAppShare } from '@/hooks/core/useAppShare';
  import { getUrl, onLoad, redirectTo } from '@/router';
  import type { ApplyCooperationResult } from '@/router/types/modules';
  import { useUserStore } from '@/store/modules/user';
  import { onShareAppMessage } from '@dcloudio/uni-app';
  import { ref } from 'vue';

  const { setWxSharePath } = useAppShare();
  const { userInfo } = useUserStore();
  const routeOptions = ref<ApplyCooperationResult>();
  const confirmText = ref<string>();
  const title = ref<string>();
  const content = ref<string>();
  onLoad<'applyCooperationResult'>((op) => {
    wx.hideShareMenu({
      menus: ['shareAppMessage', 'shareTimeline'],
    });
    routeOptions.value = op;
    if (op.type === ApplicationTypeEnum.direct) {
      title.value = '合作意向已发送';
      content.value = '您的合作意向已发送，请耐心等待。您也可以申请秘书处帮助进行撮合对接。';
      confirmText.value = '申请秘书处撮合';
    } else {
      title.value = '撮合申请已发送';
      content.value = '您的对接意向已发送给秘书处，请耐心等待秘书处查阅后，为您撮合对接合作。';
      confirmText.value = '邀请秘书处处理';
    }
  });

  function handleCancel() {
    // 跳转意向详情
    redirectTo({
      name: 'intentionDetails',
      options: {
        id: routeOptions.value!.id,
        type: routeOptions.value?.isIntendedRecipient ? 'received' : 'send',
      },
    });
  }

  function handleConfirm() {
    if (routeOptions.value?.type === ApplicationTypeEnum.direct) {
      redirectTo({
        name: 'requestAdminMatch',
        options: {
          id: routeOptions.value?.boInfoId,
          type: ApplicationTypeEnum.match,
        },
      });
    }
  }

  onShareAppMessage(() => {
    return {
      title: `${userInfo.userName}正在申请供需合作撮合，秘书处管理员快来帮我撮合吧~`,
      path: setWxSharePath({ name: 'cooperativeAuditDetail', options: { id: routeOptions.value?.auditRecordId! } }),
      imageUrl:
        'https://hb-saas.obs.cn-south-1.myhuaweicloud.com/mall/saas/Invitation-handling.png',
    };
  });
</script>

<style lang="scss" scoped></style>
